var fs=require("fs");
// var http=require("http");
// var server=http.createServer();
var express=require("express");
const { request, response } = require("express");
var bodyparser=require("body-parser");
// var template = require("art-template");
var app=express();
app.engine("html",require("express-art-template"));
app.use('/public/',express.static('./public/'));
app.use(bodyparser.urlencoded({extended:false}));
app.use(bodyparser.json());
var comments=[
    {
        name:'zs',
        message:'1234',
        dateTime:'20200720'
    },
    {
        name:'zs',
        message:'1234',
        dateTime:'20200720'
    },
    {
        name:'zs',
        message:'1234',
        dateTime:'20200720'
    },
    {
        name:'zs',
        message:'1234',
        dateTime:'20200720'
    },
]
app.get("/",function(request,response){
    
    response.render('../public/html/hello.html',{
        comments:comments
    })
})
app.post("/post",function(request,response){
    
    var comment=request.body;
    if((comment.name!="")&&(comment.message!="")){
        comment.dateTime=20200720;
        comments.unshift(comment);
        console.log(comments);
        response.redirect("/");
    }
    else{
        response.redirect("/public/html/liuyan.html")
    }
    

})
app.listen(3000,function(request,response){
    console.log("serving start");
})